﻿using System;
using System.Collections.Generic;
using com.yoozoo.gta.Gameplay.RTS;
using TMPro;
using UnityEngine;
using UnityEngine.Profiling;
using XLua;
using Yoozoo.Gameplay.RTS.Proto;
using Yoozoo.UI.YGUI;

namespace Yoozoo.Gameplay.RTS
{
    public class MonsterHud : HudBase
    {
        private const float Duration = 0.1f;
        private MonsterHudLod0 _monsterHudLod0;

        private readonly Vector3 _unSelectScale = new Vector3(0.8f, 0.8f, 0.8f);

        // 野怪HUD包含两层LOD，其中第一级LOD中在战斗状态要显示英雄头像
        // lod0: MonsterHudLOD0.prefab + ArmyInfo.prefab
        // lod1: MonsterHudLOD1.prefab
        private GameObject _monsterLod0Obj;
        private int _initSoldierCount;
        private float _lodPercent;
        private float _lodScale;
        private MonsterHudLod1 _monsterHudLod1;
        private int _oldSoldierCount;
        private int _soldierCount;
        private float _timer;

        // 0 不发生改变 1头像往中间 -1 头像往左边
        private int _tweenCode;
        protected bool _lod0Visible = false;
        protected bool _lodMonster0Visible = false;
        private MonsterRadarIcon RadarIcon;
        private GameObject RadarIconObj;
        public MonsterHud()
        {
            HudType = HudType.Monster;
        }

        protected void BaseInitialize(int team)
        {
            base.Initialize(team);
        }
        
        public override void Initialize(int team)
        {
            base.Initialize(team);
            var hudManager = ArmyManager.Instance.HudManager;
            _marchLodLevel = -1;

            if (Lod0 == null)
            {
                Lod0 = hudManager.GetHud(HudManager.MarchHudLod0);
            }
           
            _lod0Visible = Lod0.activeInHierarchy;
            MarchHudLod0 = Lod0?.GetComponent<MarchHudLod0>();
            MarchHudLod0.hudRef = this;
            var rtsServerData = MarchEntity.RtsServerInfo;
            if (rtsServerData.npcType == RtsNpcType.NPC_MONSTER)
            {
                if (_monsterLod0Obj == null)
                {
                    _monsterLod0Obj = hudManager.GetHud(HudManager.MonsterHudLod0);
                }
                
                if (Lod1 == null)
                {
                    Lod1 = hudManager.GetHud(HudManager.MonsterHudLod1);
                }
            }
            else if (rtsServerData.npcType == RtsNpcType.NPC_BELT_MONSTER)
            {
                if (_monsterLod0Obj == null)
                {
                    _monsterLod0Obj = hudManager.GetHud(HudManager.LohaHudLod0);
                }
                if (Lod1 == null)
                {
                    Lod1 = hudManager.GetHud(HudManager.LohaHudLod1);
                }
            }
            else if (rtsServerData.npcType == RtsNpcType.NPC_BKI_ARMY)
            {
                if (_monsterLod0Obj == null)
                {
                    _monsterLod0Obj = hudManager.GetHud(HudManager.BkiArmyLod0);
                }
                if (Lod1 == null)
                {
                    Lod1 = hudManager.GetHud(HudManager.BkiArmyLod1);
                }
            }
            else if (rtsServerData.npcType == RtsNpcType.NPC_DONALD_KILLER)
            {
                if (_monsterLod0Obj == null)
                {
                    _monsterLod0Obj = hudManager.GetHud(HudManager.BkiArmyLod0);
                }
                if (Lod1 == null)
                {
                    Lod1 = hudManager.GetHud(HudManager.BkiArmyLod1);
                }
            }
            else
            {
                if (_monsterLod0Obj == null)
                {
                    _monsterLod0Obj = hudManager.GetHud(HudManager.MonsterHudLod0);
                }
                
                if (Lod1 == null)
                {
                    Lod1 = hudManager.GetHud(HudManager.MonsterHudLod1);
                }

                if (rtsServerData.npcType == RtsNpcType.NPC_SP_MONSTER || rtsServerData.npcType == RtsNpcType.NPC_SANTA)
                {
                    SetNickName(rtsServerData.name);
                }
            }
            _monsterHudLod0 = _monsterLod0Obj?.GetComponent<MonsterHudLod0>();
            if (_monsterLod0Obj != null) 
                _lodMonster0Visible = _monsterLod0Obj.activeInHierarchy;

            if (rtsServerData.radarEventQuality != 0)
            {
                RadarIconObj = hudManager.GetHud(HudManager.MonsterRadarIcon);
                RadarIcon = RadarIconObj.GetComponent<MonsterRadarIcon>();
            }
            _monsterHudLod1 = Lod1?.GetComponent<MonsterHudLod1>();
            InitAlpha();
            inBattleStateChangedAction += OnBattleStateChangedActionChanged;
        }
        
        public override void Show()
        {
            base.Show();
            SetLod0Visible(MarchManager.Instance.marchContext,true);
        }

        public virtual void UpdateMonsterInfo()
        {
            if (RadarIcon == null)
            {
                if (MarchEntity.RtsServerInfo.radarEventQuality != 0)
                {
                    var hudManager = ArmyManager.Instance.HudManager;
                    RadarIconObj = hudManager.GetHud(HudManager.MonsterRadarIcon);
                    RadarIcon = RadarIconObj.GetComponent<MonsterRadarIcon>();
                    //RadarIconObj.transform.SetParent(MarchEntity.Transform);
                    RadarIconObj.transform.localPosition = Vector3.zero;
                    
                    if (_marchLodLevel >= WorldEntry.MaxShowMarchLodLevel)
                    {
                        RadarIcon?.SetIconActive(false);
                    }
                    else
                    {
                        
                        RadarIcon?.SetIconActive(IsShowRadarIcon(GetFactorValue(EHeadFactor.IsInBattle)));
                    }
                    SetHudLodScale(LodHudType.MonsterRadarHud, RadarIconObj, MarchManager.Instance.marchContext);
                }
            }
            UpdateRadarIcon();
        }
        protected bool IsInBattleState => MarchEntity.MarchInfo.IsInBattleState;

        protected override void OnCommanderHeadInBattleStateChanged(bool value)
        {
            base.OnCommanderHeadInBattleStateChanged(value);
            _monsterHudLod0?.SetActive(!value);
        }
        public void SetEntityAndTroopData(MarchEntity marchEntity, RtsServerInfo troopMarch)
        {
            MarchEntity = marchEntity;
            _heroIconList = troopMarch.heroIconList;
        }

        public override void OnCameraPosUpdated(MarchContext marchContext)
        {
            // 此时所有属性都已经更新完毕，根据这些属性更新UI
            LodLevelChange(marchContext.LodLevel, marchContext.LodPercent, marchContext);
        }

        protected override void OnUpdateLowLod(MarchContext marchContext)
        {
            base.OnUpdateLowLod(marchContext);
            SetLod0Visible(marchContext);
        }


        public override void SetSelected(bool value, bool isMultySelect)
        {
            _isSelected = value;
//            MarchHudLod0.CommanderHead?.BaseArmyInfo.SetSelect(_isSelected, MarchEntity.MarchInfo.IsInBattleState, false, true);
        }

        public override void Dispose()
        {
            // 释放
            var hudManager = ArmyManager.Instance.HudManager;

            hudManager.RecoverHud(HudManager.MarchHudLod0, Lod0);
            Lod0 = null;
            MarchHudLod0.Dispose();
            RemoveCommanderHead(true);
            MarchHudLod0 = null;
            if (MarchEntity.RtsServerInfo.npcType == RtsNpcType.NPC_MONSTER)
            {
                if (_monsterLod0Obj)
                {
                    hudManager.RecoverHud(HudManager.MonsterHudLod0, _monsterLod0Obj);
                }

                if (Lod1)
                {
                    hudManager.RecoverHud(HudManager.MonsterHudLod1, Lod1);
                }
            }
            else if (MarchEntity.RtsServerInfo.npcType == RtsNpcType.NPC_BKI_ARMY)
            {
                if (_monsterLod0Obj)
                {
                    hudManager.RecoverHud(HudManager.BkiArmyLod0, _monsterLod0Obj);
                }

                if (Lod1)
                {
                    hudManager.RecoverHud(HudManager.BkiArmyLod1, Lod1);
                }
            }
            else if (MarchEntity.RtsServerInfo.npcType == RtsNpcType.NPC_DONALD_KILLER)
            {
                if (_monsterLod0Obj)
                {
                    hudManager.RecoverHud(HudManager.BkiArmyLod0, _monsterLod0Obj);
                }

                if (Lod1)
                {
                    hudManager.RecoverHud(HudManager.BkiArmyLod1, Lod1);
                }
            }
            else
            {
                if (_monsterLod0Obj)
                {
                    hudManager.RecoverHud(HudManager.LohaHudLod0, _monsterLod0Obj);
                }

                if (Lod1)
                {
                    hudManager.RecoverHud(HudManager.LohaHudLod1, Lod1);
                }
            }

            _monsterHudLod0?.Dispose();
            _monsterLod0Obj = null;
            Lod1 = null;

            MarchHudLod0 = null;

            _monsterHudLod1 = null;
            
            MarchEntity = null;
            hasSetParent = false;
            RadarHudDispose();
            inBattleStateChangedAction -= OnBattleStateChangedActionChanged;
            base.Dispose();
        }
        
        protected void RadarHudDispose()
        {
            var hudManager = ArmyManager.Instance.HudManager;
            if (RadarIconObj!=null)
            {
                hudManager.RecoverHud(HudManager.MonsterRadarIcon, RadarIconObj);
            }
            RadarIconObj = null;
            RadarIcon = null;
        }

        protected void BaseDispose()
        {
            base.Dispose();
        }

        public override void Hide()
        {
            RemoveCommanderHead(true);
            if (_monsterLod0Obj)
            {
                _monsterLod0Obj.transform.position = invisiblePosition;
            }
            base.Hide();
        }
        
        protected override void OnLod1ScaleChanged(MarchContext marchContext)
        {
            if (Lod1)
            {
                base.SetHudLodScale(GetLodHighMonsterScaleType(), Lod1, marchContext);
            }
        }

        protected override void OnLod0ScaleChanged(MarchContext marchContext)
        {
            SetHudLodScale(GetLodLowMonsterScaleType(), _monsterLod0Obj, marchContext);
            SetHudLodScale(LodHudType.LodLowArmyInfo, Lod0, marchContext);
            updateRadarHud(marchContext);
        }

        public void updateRadarHud(MarchContext marchContext)
        {
            if (RadarIconObj!=null)
            {
                base.SetHudLodScale(LodHudType.MonsterRadarHud, RadarIconObj, marchContext);
            }
        }

        protected override void SelfInit()
        {
            SetTeam(MarchHelper.TeamEnemy);
        }

        protected bool hasSetParent = false;
        
       
        protected override void InitParentScaleAndPosition()
        {
            if (!hasSetParent)
            {
                //Lod0.transform.SetParent(MarchEntity.Transform);
            }
            //Lod0.transform.localPosition = lod0Offset;
            if (!hasSetParent)
            {
                //_monsterLod0Obj.transform.SetParent(MarchEntity.Transform);
            }
            //_monsterLod0Obj.transform.localPosition = monterLod0Offset;
            if (Lod1 != null)
            {
                // if (!hasSetParent)
                // {
                //     Lod1.transform.SetParent(MarchEntity.Transform);
                // }
                // Lod1.transform.localPosition = lod1Offset;
                Lod1.transform.localScale = locallod1Scale;
            }
            //if (!hasSetParent && RadarIconObj!=null)
            //{
                //RadarIconObj.transform.SetParent(MarchEntity.Transform);
                //RadarIconObj.transform.localPosition = RadarIconObjOffset;
            //}
            hasSetParent = true;
        }
        //private Vector3 lod0Offset = new Vector3(0f, 0.0f, 0.0f);
        private Vector3 monterLod0Offset = new Vector3(-0.23f, 0.057f, -0.22f);
        private Vector3 lod1Offset = new Vector3(-0.23f, 0.057f, -0.22f);
        private Vector3 locallod1Scale = new Vector3(0.1f, 0.1f, 0.1f);
        //private Vector3 RadarIconObjOffset = Vector3.zero;
        public override void UpdateFollowPos()
        {
            
            if (hasSetParent)
            {
                var parentPos = MarchEntity.Transform.position;
                if (Lod0 != null)
                {
                    Lod0.transform.localPosition =  parentPos;
                }

                if (_monsterLod0Obj != null)
                {
                    _monsterLod0Obj.transform.localPosition = monterLod0Offset+ parentPos;
                }
                
                if (Lod1 != null)
                {
                    Lod1.transform.localPosition = lod1Offset + parentPos;
                }
                
                if (RadarIconObj!=null)
                {
                    RadarIconObj.transform.localPosition =  parentPos ;
                }
            }
        }
        private string map_levelbg_03 = "map_levelbg_03";
        private string map_levelbg = "map_levelbg";
        public override void UpdatePlayerName()
        {
            // 初始化，设置不变的部分，玩家名、阵营以及英雄头像
            // 设置玩家名和颜色，仅lod0
            MarchHudLod0.PlayerNameText.text = MarchEntity.RtsServerInfo.name;
            MarchHudLod0.PlayerNameBg.gameObject.SetActive(false);
            //MarchHudLod0.OtherBattleInfo.SetBasicInfo(_troopMarch.lod1.monsterName);
            MarchHudLod0.StateIcon.enabled = false;
            MarchHudLod0.StateIconBg.enabled = false;
            if (MarchEntity.RtsServerInfo.npcType == RtsNpcType.NPC_MONSTER)
            {
                var level = MarchEntity.RtsServerInfo.level.ToString();
                _monsterHudLod0.LevelText.text = level;
                _monsterHudLod1.LevelText.text = level;
                if (RadarIcon != null)
                {
                    UpdateRadarIcon();
                }
                else
                {
                    _monsterHudLod0.SetRtsLevelBg(map_levelbg);
                }

                var icon = MarchEntity.RtsServerInfo.heroBgIcon;
                if (!string.IsNullOrEmpty(icon))
                {
                    _monsterHudLod1.SetIcon(icon);
                }
            }
            else if (MarchEntity.RtsServerInfo.npcType == RtsNpcType.NPC_BKI_ARMY || MarchEntity.RtsServerInfo.npcType == RtsNpcType.NPC_CARGO_MONSTER)
            {
                var level = MarchEntity.RtsServerInfo.level.ToString();
                _monsterHudLod0.LevelText.text = level;
                _monsterHudLod1.LevelText.text = level;
                _monsterHudLod1.SetMapIcon(MarchEntity.RtsServerInfo.heroBgIcon);
            }
            else if (MarchEntity.RtsServerInfo.npcType == RtsNpcType.NPC_DONALD_KILLER)
            {
                var level = MarchEntity.RtsServerInfo.level.ToString();
                _monsterHudLod0.LevelText.text = level;
                _monsterHudLod1.LevelText.text = level;
                _monsterHudLod1.SetMapIcon(MarchEntity.RtsServerInfo.heroBgIcon);
            }
            else if (MarchEntity.RtsServerInfo.npcType == RtsNpcType.NPC_BELT_MONSTER)
            {
                if (_monsterHudLod0.LevelText!=null)
                {
                    _monsterHudLod0.LevelText.text = "";

                }if (_monsterHudLod1.LevelText!=null)
                {
                    _monsterHudLod1.LevelText.text = "";
                }
                _monsterHudLod0.SetLohaBgIcon(MarchEntity.RtsServerInfo.heroBgIcon);
                _monsterHudLod1.SetIcon("");
                _monsterHudLod1?.SetLevelBgIcon(MarchEntity.RtsServerInfo.heroBgIcon);
            }
            else if (MarchEntity.RtsServerInfo.npcType == RtsNpcType.NPC_SP_MONSTER)
            {
                SetNickName(MarchEntity.RtsServerInfo.name);
                MarchHudLod0.PlayerNameText.color = MarchHelper.TeamTxtColors[_team];
                MarchHudLod0.SetNickNameColor(MarchHelper.TeamTxtColors[_team]);
                MarchHudLod0.PlayerNameBg.gameObject.transform.localPosition = new Vector3(0,85,0);
                MarchHudLod0.SetNickNamePosition(true);
                
                var level = MarchEntity.RtsServerInfo.level.ToString();
                _monsterHudLod0.LevelText.text = level;
                _monsterHudLod1.LevelText.text = level;
                if (MarchEntity.RtsServerInfo.isShowAssemblyHeadFrame)
                {
                    _monsterHudLod0.SetLevelBg("map_wavebg_01");
                    _monsterHudLod1.SetLevelBgIcon("map_wavebg_01");
                }
                else
                {
                    _monsterHudLod0.SetLevelBg("map_levelbg_04");
                    _monsterHudLod1.SetLevelBgIcon("map_levelbg_04");
                }
                _monsterHudLod1.SetMapElementIcon(MarchEntity.RtsServerInfo.heroBgIcon);
            }
            else if (MarchEntity.RtsServerInfo.npcType == RtsNpcType.NPC_SANTA)
            {
                SetNickName(MarchEntity.RtsServerInfo.name);
                MarchHudLod0.PlayerNameText.color = MarchHelper.TeamTxtColors[_team];
                MarchHudLod0.SetNickNameColor(MarchHelper.TeamTxtColors[_team]);
                MarchHudLod0.PlayerNameBg.gameObject.transform.localPosition = new Vector3(0, 85, 0);
                MarchHudLod0.SetNickNamePosition(true);
                if (MarchEntity.RtsServerInfo.isShowAssemblyHeadFrame)
                {
                    _monsterHudLod0.LevelText.text = "";
                    _monsterHudLod1.LevelText.text = "";
                    _monsterHudLod0.SetLevelBg("icon_map_WonderTroops_2");
                    _monsterHudLod1.SetLevelBgIcon("icon_map_WonderTroops_2");
                }
                else
                {
                    var level = MarchEntity.RtsServerInfo.level.ToString();
                    _monsterHudLod0.LevelText.text = level;
                    _monsterHudLod1.LevelText.text = level;
                    _monsterHudLod0.SetLevelBg("map_levelbg_04");
                    _monsterHudLod1.SetLevelBgIcon("map_levelbg_04");
                }
                _monsterHudLod1.SetMapElementIcon(MarchEntity.RtsServerInfo.heroBgIcon);
            }
        }
        
        public void UpdateRadarIcon()
        {
            if (RadarIcon != null)
            {
                int type = MarchEntity.RtsServerInfo.radarEventType;
                string icon = MarchEntity.RtsServerInfo.radarEventRewardIcon;

                if (MarchEntity.RtsServerInfo.radarEventType == 8)
                {
                    RadarIcon.SetRaderQualityIcon02(99, MarchEntity.RtsServerInfo.radarEventType);
                    RadarIcon.SetRadarRewardIcon("");
                    RadarIcon.SetRadarEquipTypeImage(MarchEntity.RtsServerInfo.radarEquipType);
                    RadarIcon.SetRadarLeftUpIconImage("");
                    if (_monsterHudLod0 != null)
                    {
                        _monsterHudLod0.SetRtsLevelBg(map_levelbg);
                    }
                }
                else
                {
                    if (MarchEntity.RtsServerInfo.radarEventQuality == 6)
                    {
                        RadarIcon.SetRaderQualityIcon02(99, MarchEntity.RtsServerInfo.radarEventQuality);
                        RadarIcon.SetMonsterIconIcon("");
                        RadarIcon.SetRadarEquipTypeImage(MarchEntity.RtsServerInfo.radarEquipType);
                        RadarIcon.SetRadarLeftUpIconImage("");
                        _monsterHudLod0.SetRtsLevelBg(map_levelbg_03);
    //                    _monsterHudLod0.SetLevelTextColor(Color.white);
                    }
                    else
                    {
                        if (MarchEntity.RtsServerInfo.radarType == 6)
                        {
                            RadarIcon.SetRaderQualityIcon02(MarchEntity.RtsServerInfo.radarType, MarchEntity.RtsServerInfo.radarEventQuality);
                            RadarIcon.SetRadarRewardIcon(MarchEntity.RtsServerInfo.radarEventRewardIcon);
                            RadarIcon.SetRadarEquipTypeImage("");
                            RadarIcon.SetRadarLeftUpIconImage("");
                        }
                        else
                        {
                            RadarIcon.SetRaderQualityIcon02(MarchEntity.RtsServerInfo.radarEventType, MarchEntity.RtsServerInfo.radarEventQuality);
                            RadarIcon.SetRadarRewardIcon(MarchEntity.RtsServerInfo.radarEventRewardIcon);
                            RadarIcon.SetRadarEquipTypeImage(MarchEntity.RtsServerInfo.radarEquipType);
                            RadarIcon.SetRadarLeftUpIconImage("");
                            _monsterHudLod0.SetRtsLevelBg(map_levelbg);
                        }
                        //                    _monsterHudLod0.SetLevelTextColor(Color.black);
                    }
                }
                
            }
            
        }

        protected override void InitSoldierNumAndRage()
        {
            int rageMax = MarchEntity.RtsServerInfo.MaxRage;
            MaxRage = rageMax;
            _initSoldierCount = MarchEntity.RtsServerInfo.initSoldierCount;
        }

        protected override void InitDefaultTrigger()
        {
            if (MarchHudLod0!=null)
            {
                if (MarchHudLod0.CommanderHead)
                {
                    _marchHudLod0BattleLineEnabled = MarchHudLod0.CommanderHead.BattleLine.enabled;
                }
            }
        }
        
        protected override void OnPlayerNameVisibleChanged(bool value)
        {
            if (MarchHudLod0 != null)
            {
                if (MarchEntity.RtsServerInfo.npcType == RtsNpcType.NPC_SP_MONSTER || MarchEntity.RtsServerInfo.npcType == RtsNpcType.NPC_SANTA)
                { 
                    MarchHudLod0.PlayerNameBg.gameObject.SetActive(value);
                    if (value)
                    {
                        MarchHudLod0.PlayerNameText.color = MarchHelper.TeamTxtColors[_team];
                        MarchHudLod0.SetNickNameColor(MarchHelper.TeamTxtColors[_team]);
                    }
                    MarchHudLod0.SetNickNameVisiable(value);
                }
                else
                {
                    MarchHudLod0.PlayerNameBg.gameObject.SetActive(false);
                    MarchHudLod0.SetNickNameVisiable(false);
                }
            }
        }

        protected void SetRadarIconActive(bool value)
        {
            RadarIcon?.SetIconActive(value);
        }

        private bool IsShowRadarIcon(bool battleState)
        {
            bool isInBattle = battleState;
            return !isInBattle;
        }

        private void OnBattleStateChangedActionChanged(bool battleState)
        {
            var active = IsShowRadarIcon(battleState);
            RadarIcon?.SetIconActive(active);
        }

        private void UpdateLod0Scale(MarchContext context)
        {
            float newLod0Scale = context.Lod0Scale;
            // 更新Lod0
            if (Mathf.Abs(_lodScale - newLod0Scale) > 0.00001f)
            {
                _lodScale = newLod0Scale;
                if (MarchHudLod0!=null)
                {
                    MarchHudLod0.transform.localScale = new Vector3(_lodScale, _lodScale, _lodScale);
                }
            }
        }
        private void LodLevelChange(int currentLodLevel, float currentLodPercent, MarchContext marchContext)
        {
            if (_marchLodLevel <= WorldEntry.MaxShowMarchLodLevel)
            {
                UpdateLod0Scale(marchContext);
            }
            // 先处理LOD
            if (currentLodLevel != _marchLodLevel)
            {
                OnLodLevelChange(currentLodLevel);
                SetLod0Visible(marchContext);
            }
         
            if (_monsterHudLod1)
            {
                if (currentLodLevel >= WorldEntry.MaxShowMarchLodLevel)
                {
                    // if (currentLodLevel == WorldEntry.MaxShowMarchLodLevel && currentLodPercent < 80)
                    // {
                    // }
                    // else
                    // {
                    //     _monsterHudLod1.SetLevelVisible(false);
                    // }
                    _monsterHudLod1.SetLevelVisible(true);
                    _monsterHudLod1.SetIconVisible(true);
                    RadarIcon?.SetIconActive(false);
                }
                else
                {
                    _monsterHudLod1.SetLevelVisible(false);
                    _monsterHudLod1.SetIconVisible(false);
                    RadarIcon?.SetIconActive(IsShowRadarIcon(GetFactorValue(EHeadFactor.IsInBattle)));
                }
            }
        }
        protected virtual void SetLod0Visible(MarchContext marchContext,bool force = false)
        {
            bool isShowLod0 = marchContext.LodLevel < WorldEntry.MaxShowMarchLodLevel;
            bool lod0Visible = isShowLod0 || IsInBattleState;
            if (_lodMonster0Visible != isShowLod0 || force)
            {
                if (!isShowLod0)
                {
                    _monsterLod0Obj.transform.localScale = Vector3.zero;
                }
                else
                {
                    base.SetHudLodScale(GetLodLowMonsterScaleType(), _monsterLod0Obj, marchContext);
                }
                _lodMonster0Visible = isShowLod0;
            }
            if (_lod0Visible != lod0Visible || force)
            {
                if (!lod0Visible)
                {
                    Lod0.transform.localScale = Vector3.zero;
                }
                else
                {
                    base.SetHudLodScale(LodHudType.LodLowArmyInfo, Lod0, marchContext);
                }

                if (MarchEntity.RtsServerInfo.npcType == RtsNpcType.NPC_SP_MONSTER || MarchEntity.RtsServerInfo.npcType == RtsNpcType.NPC_SANTA)
                {
                    MarchHudLod0.SetNickNameVisiable(lod0Visible);
                    UpdatePlayerName();
                }
                _lod0Visible = lod0Visible;
            }
        

        }
        
        /// <summary>
        /// 沙盒的LOD切换后，切换相应的LOD物件
        /// </summary>
        /// <param name="currentLodLevel"></param>
        private void OnLodLevelChange(int currentLodLevel)
        {
            // LOD <  2: LOD0
            // LOD >= 2: LOD1
            if (_marchLodLevel != currentLodLevel)
            {
                _marchLodLevel = currentLodLevel;
            }
    
        }
        public override void ForceShowSelectedUI(bool isShow,bool isBattleStyle)
        {
            _forceShowHud = isShow;
            _isBattleStyle = isBattleStyle;
            SetHeadFactor(EHeadFactor.IsForceShow,isShow);
            SetHeadFactor(EHeadFactor.IsBattleStyle,isBattleStyle);
        }

        public LodHudType GetLodLowMonsterScaleType()
        {
            var rtsServerData = MarchEntity.RtsServerInfo;
            switch (rtsServerData.npcType)
            {
                case RtsNpcType.NPC_MONSTER:
                case RtsNpcType.NPC_MIRACLE_GUARD:
                case RtsNpcType.NPC_MIRACLE_MOBILIZATION:
                case RtsNpcType.NPC_MIRACLE_REINFORCE:
                case RtsNpcType.NPC_SP_MONSTER:
                    return LodHudType.MonsterLodLowHudMini;
                case RtsNpcType.NPC_BELT_MONSTER://贝尔特
                case RtsNpcType.NPC_SMUGGLER:
                case RtsNpcType.NPC_BKI_ARMY:
                    return LodHudType.MonsterLodLowHudMiddle;
                case RtsNpcType.NPC_DONALD_KILLER:
                case RtsNpcType.NPC_PRACTICE_BOSS:
                case RtsNpcType.NPC_WORLD_BOSS:
                    return LodHudType.MonsterLodLowHudMax;
                default:
                    return LodHudType.MonsterLodLowHudMini;
            }
        }
        public LodHudType GetLodHighMonsterScaleType()
        {
            var rtsServerData = MarchEntity.RtsServerInfo;
            switch (rtsServerData.npcType)
            {
                case RtsNpcType.NPC_MONSTER:
                case RtsNpcType.NPC_MIRACLE_GUARD:
                case RtsNpcType.NPC_MIRACLE_MOBILIZATION:
                case RtsNpcType.NPC_MIRACLE_REINFORCE:
                case RtsNpcType.NPC_SP_MONSTER:
                    return LodHudType.MonsterLodHighHudMini;
                case RtsNpcType.NPC_BELT_MONSTER:
                case RtsNpcType.NPC_SMUGGLER:
                case RtsNpcType.NPC_BKI_ARMY:
                    return LodHudType.MonsterLodHighHudMiddle;
                case RtsNpcType.NPC_DONALD_KILLER:
                case RtsNpcType.NPC_PRACTICE_BOSS:
                case RtsNpcType.NPC_WORLD_BOSS:
                    return LodHudType.MonsterLodHighHudMax;
                default:
                    return LodHudType.MonsterLodHighHudMini;
            }
        }
    }
}
